package com.shanjupay.paymentagent.controller;

import com.alibaba.fastjson.JSON;
import com.shanjupay.paymentagent.api.conf.AliConfigParam;
import com.shanjupay.paymentagent.api.dto.AlipayBean;
import com.shanjupay.paymentagent.api.dto.PaymentResponseDTO;
import com.shanjupay.paymentagent.api.service.IPayChannelAgentService;
import com.zpark.jushanpay.common.domain.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付代理服务控制层
 */
@RestController
@RequestMapping("/agent_pay")
public class PayChannelAgentController {

    // 字段注入业务层对象
    @Autowired
    private IPayChannelAgentService payChannelAgentService;

    /**
     * 调用支付宝手机WAP下单接口
     * @param bean
     * @return
     */
    @RequestMapping("/ali_wap")
    public RestResponse<PaymentResponseDTO> createPayOrderByAliWAP(
            @RequestParam("paramStr") String paramStr, @RequestBody AlipayBean bean) {

        // 将支付参数json字符串转为支付配置对象
        AliConfigParam aliConfigParam = JSON.parseObject(paramStr, AliConfigParam.class);
        // 设置编码方式
        aliConfigParam.setCharset("utf-8");

        // 调用业务层方法完成支付
        return RestResponse.success(
                payChannelAgentService.createPayOrderByAliWAP(aliConfigParam, bean)
        );
    }
}
